import { createRouter, createWebHistory } from 'vue-router'
const Login=()=>import("../views/Login.vue");//登录页面
const Index=()=>import("../views/Index.vue");//登录页面

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
     {
       path:"/",
       redirect:"/login"
     },
     {
      path:"/login",
      name:"Login",
      meta:{
          title:"登录"
      },
      component:Login
     },
     {
      path:"/index",
      beforeEnter(to,from,next){
         let token=sessionStorage.getItem("token")
         if(token){
          next()
         }else{
           next("/login")
         }
      },
      redirect:"/index/system",
      name:"Index",
      meta:{
          title:"首页"
      },
      component:Index,
      children:[
        // dashboard模块
          {
            path:"system",
            name:"System",
            meta:{title:"系统介绍"},
            component:()=>import("../views/dashboard/System.vue")
          },
          {
            path:"dashboard",
            name:"Dashboard",
            meta:{title:"dashboard"},
            component:()=>import("../views/dashboard/Dashboard.vue")
          },
          {
            path:"addgoods",
            name:"Addgoods",
            meta:{title:"添加商品"},
            component:()=>import("../views/dashboard/Addgoods.vue")
          },
          // 首页配置
          {
            path:"loopimgset",
            name:"Loopimgset",
            meta:{title:"轮播图配置"},
            component:()=>import("../views/indexset/Loopimgset.vue")
          },
          {
            path:"hotgoodsset",
            name:"Hotgoodsset",
            meta:{title:"热销商品配置"},
            component:()=>import("../views/indexset/Hotgoodsset.vue")
          },
          {
            path:"newgoodsset",
            name:"Newgoodsset",
            meta:{title:"新品上线配置"},
            component:()=>import("../views/indexset/Newgoodsset.vue")
          },
          {
            path:"recomment",
            name:"Recomment",
            meta:{title:"为你推荐配置"},
            component:()=>import("../views/indexset/Recomment.vue")
          },
          // 模块管理
          {
            path:"typemanger",
            name:"Typemanger",
            meta:{title:"分类管理"},
            component:()=>import("../views/modulemanger/Typemanger.vue")
          },
          {
            path:"goodsmanger",
            name:"Goodsmanger",
            meta:{title:"商品管理"},
            component:()=>import("../views/modulemanger/Goodsmanger.vue")
          },
          {
            path:"vipmanger",
            name:"Vipmanger",
            meta:{title:"会员管理"},
            component:()=>import("../views/modulemanger/Vipmanger.vue")
          },
          {
            path:"ordermanger",
            name:"Ordermanger",
            meta:{title:"订单管理"},
            component:()=>import("../views/modulemanger/Ordermanger.vue")
          },

          // 系统管理

          {
            path:"updatepwd",
            name:"Updatepwd",
            meta:{title:"修改密码"},
            component:()=>import("../views/sysmanger/Updatepwd.vue")
          },
      ]
     }
  ]
})

router.beforeEach((to,from,next)=>{
   document.title=to.meta.title 

  next();
})

export default router
